﻿#include <cmath>
#include <QDebug>
#include <QFontMetrics>
#include "element.h"

DrawText::DrawText(void)
{
    m_text = "";
    m_drawType = TEXT;
    m_state = DS_IDLE;
}


void DrawLine::build(QPoint start, QPoint end)
{
    setStartPoint(start);
    setEndPoint(end);
}

int DrawLine::mouseLButtonPress(QPoint point)
{
    if( m_state == DS_IDLE )
    {
        setStartPoint(point);
        return 1;
    }
    return 0;
}


void DrawLine::updateText(void)
{
    QFontMetrics fm(m_textFont);
    int textWidth = fm.width(m_text);
    int textHeight = fm.height();
    m_textBox.setWidth(textWidth);
    m_textBox.setHeight(textHeight);

}

void DrawLine::draw( QPainter &painter )
{
    if( m_state != DS_IDLE )
    {
        painter.save();
        painter.setPen(m_linePen);
        painter.setFont(m_textFont);
        painter.drawText(m_textBox, m_text);
        painter.restore();
    }
}

